#! /usr/bin/python3
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
	raise Exception("不支持从这里调用")

__version__ = "1.0"
__all__ = [
	"MouseChshField",
	"MouseChshIntegerField",
	"MouseChshStringField",
	"MouseChshJsonBinField",
	"MouseChshDateTimeField",
	"MouseChshForeignStringField",
]


class MouseChshField:

	def __init__(
		self, column_type, column_prefix, column_name, *, linked_table='', max_length=-1, default=None, **args_dict
	):
		self.__column_type = column_type
		self.__column_prefix = column_prefix
		self.__column_name = column_name
		self.__linked_table = linked_table
		self.__max_length = max_length
		self.__default = default

	def get_key(self):
		if self.__linked_table:
			return self.__linked_table
		return self.__column_name

	def get_column_type(self):
		return self.__column_type

	def get_column_prefix(self):
		return self.__column_prefix

	def get_column_name(self):
		return self.__column_name

	def get_linked_table(self):
		return self.__linked_table if self.__linked_table else self.__column_name

	def get_full_column_name(self, changed_prefix=''):
		return (changed_prefix if changed_prefix else self.__column_prefix) + '_' + (
			self.__linked_table + '_' if self.__linked_table else '') + self.__column_name

	def get_max_length(self):
		return self.__max_length

	def get_default(self):
		return self.__default

	def to_string(self):
		return self.get_full_column_name()


class MouseChshBooleanField(MouseChshField):

	def __init__(self, column_name, *, default=0, **args_dict):
		super().__init__('boolean', 'C', column_name, default=default, **args_dict)

	def to_string(self):
		return self.get_full_column_name() + ' as boolean'


class MouseChshIntegerField(MouseChshField):

	def __init__(self, column_name, *, default=0, **args_dict):
		super().__init__('integer', 'C', column_name, default=default, **args_dict)

	def to_string(self):
		return self.get_full_column_name() + ' as integer'


class MouseChshStringField(MouseChshField):

	def __init__(self, column_name, *, max_length=-1, **args_dict):
		super().__init__('varchar', 'C', column_name, max_length=max_length, **args_dict)

	def to_string(self):
		return self.get_full_column_name() + ' as varchar(' + str(self.__max_length) + ')'


class MouseChshJsonBinField(MouseChshField):

	def __init__(self, column_name, **args_dict):
		super().__init__('jsonb', 'X', column_name, **args_dict)

	def to_string(self):
		return self.get_full_column_name() + ' as jsonb'


class MouseChshDateTimeField(MouseChshField):

	def __init__(self, column_name, **args_dict):
		super().__init__('datetime', 'C', column_name, **args_dict)

	def to_string(self):
		return self.get_full_column_name() + ' as datetime'


class MouseChshForeignStringField(MouseChshField):

	def __init__(self, column_name, *, linked_table='', max_length=-1, **args_dict):
		super().__init__('varchar', 'L', column_name, linked_table=linked_table, max_length=max_length, **args_dict)

	def to_string(self):
		return self.get_full_column_name() + ' as varchar(' + str(self.__max_length) + ') FK'
